package com.google.gwt.gfx.client.layers;

import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.gfx.client.overlays.GFXImage;
import com.google.gwt.gfx.client.services.StretchService;

/**
 * A type of {@link Layer} that represents raster data as a image covering the
 * window size specified by {@link #viewport()}.
 * 
 * @see StretchService
 */
public class StretchLayer<S extends StretchService<?>> extends Layer<S> {

	private GFXImage stretch;

	public StretchLayer() {
		super();

		addStyleName("gfx-StretchLayer");

		stretch = GFXImage.get(getStyleName(), "#");
		add(stretch);
	}

	@Override
	public void refresh() {
		Style style = stretch.getElement().getStyle();
		style.setWidth(service().viewport().getWidth(), Unit.PX);
		style.setHeight(service().viewport().getHeight(), Unit.PX);
		style.setLeft(-getElement().getOffsetLeft(), Unit.PX);
		style.setTop(-getElement().getOffsetTop(), Unit.PX);
		stretch.setUrl(service().getStretchUrl());
	}

}
